import { createSlice } from '@reduxjs/toolkit'
import axios from 'axios'
const billStore = createSlice({
  name:'bill',
  initialState:{
    billList:[]
  },
  reducers:{
    setBillList(state,action){
      console.log(action.payload);
      state.billList = action.payload
      
    },
    addBill(state,action){
      state.billList = action.payload
    }
  }
}) 
const { setBillList,addBill } = billStore.actions
const asyncGetBillList = ()=>{
  return async (dispatch) =>{
    const res = await axios.get('http://localhost:8888/ka')
    // console.log(res.data);
    dispatch(setBillList(res.data))
  }
}
const asyncAddBillList = (data)=>{
  return async (dispatch)=>{
    const res = await axios.post('http://localhost:8888/ka',data)
    dispatch(addBill(res.data))
}
}
const reducer = billStore.reducer
export { asyncGetBillList,asyncAddBillList}
export default reducer